xend: allow pv_ops kernel driver pci-stub to hide devices for assignment
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 6 Jul 2009 10:48:44 +0000 (11:48 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 6 Jul 2009 10:48:44 +0000 (11:48 +0100)
pciback is used by VT-d to hide device for assigment. But in pv-ops
dom0, pciback is not supported yet. Fortunately, pci-stub module is
used to hide device in Linux for KVM VT-d device assignment and it's
included in pv-ops dom0. So can use pci-stub to hide devices for
assignment.

Device must be hidden before assignment. Control panel has checks if
devices can be assigned or not, and can list assignable devices via
reading devices owned by pciback. This patch changes the checks, and
also list assignable devices which are owned by pci-stub. Use pci-stub
to hide devices, and use this patch to pass checkes in control panel,
device assignemnt with VT-d works on Xen with pv-ops dom0.

Signed-off-by: Weidong Han <weidong.han@intel.com>
tools/python/xen/util/pci.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/XendNode.py
tools/python/xen/xend/server/pciif.py

index b826f8ea3ca037ba69d59c9004286952b722b899..e651d5c54450a3a8affee125860841a080f82490 100644 (file)
@@ -33,6 +33,7 @@ SYSFS_PCI_DEV_SUBVENDOR_PATH = '/subsystem_vendor'
 SYSFS_PCI_DEV_SUBDEVICE_PATH = '/subsystem_device'
 SYSFS_PCI_DEV_CLASS_PATH = '/class'
 SYSFS_PCIBACK_PATH = '/bus/pci/drivers/pciback/'
+SYSFS_PCISTUB_PATH = '/bus/pci/drivers/pci-stub/'
 
 LSPCI_CMD = 'lspci'
 
@@ -450,7 +451,10 @@ def restore_pci_conf_space(pci_cfg_list):
             os.write(fd, dw)
         os.close(fd) 
 
-def find_all_devices_owned_by_pciback():
+def find_all_assignable_devices():
+    '''  devices owned by pcibak or pci-stub can be directly assigned to
+         guest with IOMMU (VT-d or AMD IOMMU), find all these devices.
+    '''
     sysfs_mnt = find_sysfs_mnt()
     pciback_path = sysfs_mnt + SYSFS_PCIBACK_PATH
     pci_names = os.popen('ls ' + pciback_path).read()
@@ -459,6 +463,14 @@ def find_all_devices_owned_by_pciback():
     for pci in pci_list:
         dev = PciDevice(parse_pci_name(pci))
         dev_list = dev_list + [dev]
+
+    pcistub_path = sysfs_mnt + SYSFS_PCISTUB_PATH
+    pci_names = os.popen('ls ' + pcistub_path).read()
+    pci_list = extract_the_exact_pci_names(pci_names)
+    for pci in pci_list:
+        dev = PciDevice(parse_pci_name(pci))
+        dev_list = dev_list + [dev]
+
     return dev_list
 
 def transform_list(target, src):
@@ -921,10 +933,10 @@ class PciDevice:
             return
         for pci_dev in devs:
             dev = PciDevice(parse_pci_name(pci_dev))
-            if dev.driver == 'pciback':
+            if dev.driver == 'pciback' or dev.driver == 'pci-stub':
                 continue
             err_msg = 'pci: %s must be co-assigned to the same guest with %s' + \
-                ', but it is not owned by pciback.'
+                ', but it is not owned by pciback or pci-stub.'
             raise PciDeviceAssignmentError(err_msg % (pci_dev, self.name))
 
     def do_FLR(self):
index 40b81cf1ac7babfeb1ea25db446e40516b70e38c..ff38009d08a3ce5f9b4ee7bff7659644449eeb2c 100644 (file)
@@ -716,7 +716,7 @@ class XendDomainInfo:
         except Exception, e:
             raise VmError("pci: failed to locate device and "+
                     "parse it's resources - "+str(e))
-        if pci_device.driver!='pciback':
+        if pci_device.driver!='pciback' and pci_device.driver!='pci-stub':
             raise VmError(("pci: PCI Backend does not own device "+ \
                     "%s\n"+ \
                     "See the pciback.hide kernel "+ \
index 9cdcb13888abc1259065716b1ea489f364d8404c..fb08046ab8c9443d1fa22afea0ba9aba5de9426e 100644 (file)
@@ -835,7 +835,7 @@ class XendNode:
 
     def pciinfo(self):
         # Each element of dev_list is a PciDevice
-        dev_list = PciUtil.find_all_devices_owned_by_pciback()
+        dev_list = PciUtil.find_all_assignable_devices()
  
         # Each element of devs_list is a list of PciDevice
         devs_list = PciUtil.check_FLR_capability(dev_list)
index cb1e83b8541b21ade7a8f3bc7ddc0bd25b8a3423..a4c976b7bfe82f62ded331fcff457ec120e10a07 100644 (file)
@@ -224,7 +224,7 @@ class PciController(DevController):
         return sxpr    
 
     def CheckSiblingDevices(self, domid, dev):
-        """ Check if all sibling devices of dev are owned by pciback
+        """ Check if all sibling devices of dev are owned by pciback or pci-stub
         """
         if not self.vm.info.is_hvm():
             return
@@ -245,12 +245,9 @@ class PciController(DevController):
                 #no dom0 drivers bound to sdev
                 continue
 
-            if sdev.driver!='pciback':
-                raise VmError(("pci: PCI Backend does not own\n "+ \
-                    "sibling device %s of device %s\n"+ \
-                    "See the pciback.hide kernel "+ \
-                    "command-line parameter or\n"+ \
-                    "bind your slot/device to the PCI backend using sysfs" \
+            if sdev.driver!='pciback' and sdev.driver!='pci-stub':
+                raise VmError(("pci: PCI Backend and pci-stub don't\n "+ \
+                    "own sibling device %s of device %s\n"\
                     )%(sdev.name, dev.name))
         return
 
@@ -265,13 +262,9 @@ class PciController(DevController):
             raise VmError("pci: failed to locate device and "+
                     "parse it's resources - "+str(e))
 
-        if dev.driver!='pciback':
-            raise VmError(("pci: PCI Backend does not own device "+ \
-                    "%s\n"+ \
-                    "See the pciback.hide kernel "+ \
-                    "command-line parameter or\n"+ \
-                    "bind your slot/device to the PCI backend using sysfs" \
-                    )%(dev.name))
+        if dev.driver!='pciback' and dev.driver!='pci-stub':
+            raise VmError(("pci: PCI Backend and pci-stub don't own "+ \
+                    "device %s\n") %(dev.name))
 
         if dev.has_non_page_aligned_bar and arch.type != "ia64":
             raise VmError("pci: %s: non-page-aligned MMIO BAR found." % dev.name)
@@ -285,7 +278,8 @@ class PciController(DevController):
         # if arch.type != "ia64":
         #    dev.do_FLR()
 
-        PCIQuirk(dev)
+        if dev.driver == 'pciback':
+            PCIQuirk(dev)
 
         if not self.vm.info.is_hvm():
             # Setup IOMMU device assignment
@@ -437,13 +431,9 @@ class PciController(DevController):
             raise VmError("pci: failed to locate device and "+
                     "parse it's resources - "+str(e))
 
-        if dev.driver!='pciback':
-            raise VmError(("pci: PCI Backend does not own device "+ \
-                    "%s\n"+ \
-                    "See the pciback.hide kernel "+ \
-                    "command-line parameter or\n"+ \
-                    "bind your slot/device to the PCI backend using sysfs" \
-                    )%(dev.name))
+        if dev.driver!='pciback' and dev.driver!='pci-stub':
+            raise VmError(("pci: PCI Backend and pci-stub don't own device "+ \
+                    "%s\n") %(dev.name))
 
         # Need to do FLR here before deassign device in order to terminate
         # DMA transaction, etc